string s_hash[15] = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "joker", "JOKER"};

int find(const string &target)
{
    for (int i = 0; i < 15; ++i)
    {
        if (s_hash[i] == target)
        {
            return i;
        }
    }
    return -1;
}
vector<string> whatCard(string &c)
{
    vector<string> ret;
    for (int i = 0; i < c.size(); i++)
    {
        string tmp;
        while (c[i] != ' ')
        {
            tmp.push_back(c[i]);
            ++i;
        }

        if (ret.empty())
        {
            ret.push_back(tmp);
            continue;
        }
        //两张牌相同
        else if (find(tmp) == find(ret.back()))
        {
            ret.push_back(tmp);
            while (1)
            {
                tmp.clear();
                ++i;
                while (c[i] != ' ')
                {
                    tmp.push_back(c[i]);
                    ++i;
                }
                if (tmp != ret.back())
                {
                    return ret;
                }
                else
                {
                    ret.push_back(tmp);
                }
            }
        }
        //两张牌为顺子
        else if (find(tmp) > find(ret.back()))
        {
        }
        break;
    }
    return ret;
}

int main()
{
    string c;
    getline(cin, c);
    int pos = c.find('-');
    string a = c.substr(0, pos);
    string b = c.substr(pos + 1);
    auto d = whatCard(a);
    auto e = whatCard(b);

    return 0;
}